<?php
$dsn="mysql:Server=127.0.0.1;dbname=blog";
$db= new PDO($dsn, "root", "123456");
$db ->exec("set names utf8mb4");

$addTime =time();
$updateTime =$addTime;

$sql ="update article  set article_title='$articleTitle' ,category_id='$categoryId',
             intro='$intro',article_content='$articleContent' ,update_time='$updateTime'
              where article_id='$articleId' ";
$result =$db->exec($sql);

if(empty($result)){
    $log=[
        'action' => 'article_edit',
        'content' => '编辑文件成功',
        'time' => date("Y-m-d H-i-s", time()),
        'ip' => $_SERVER['REMOTE_ADDR'],
        'article_id' => $articleId,
        'article_title' => $articleTitle,
        'category_id' => $categoryId,
        'intro' => $intro,
    ];
    $file = fopen("./logs/" . date("Y-m-d") . ".txt", 'a+');
    if ($file) {
        fwrite($file, json_encode($log, JSON_UNESCAPED_UNICODE) . PHP_EOL);
        fclose($file);
    } else {
        echo "打开文件错误";
        exit();
    }
}